package admin

import (
	"github.com/gin-gonic/gin"
	"go-project/dto/requrest"
	"go-project/pkg/utils"
	"go-project/service"
	"net/http"
	"strconv"
)

type ArticleCommentController struct {
}

func (ArticleCommentController) List(c *gin.Context) {
	pagination := requrest.GeneratePaginationFormRequest(c)
	request := &requrest.ArticleCommentSearchRequest{Pagination: pagination}
	c.ShouldBind(request)
	lists, count, err := service.ArticleComment{}.FindLists(request)
	if err != nil {
		utils.Error(c, utils.ERROR, "获取数据出错", http.StatusOK)
		return
	}
	utils.PaginationSuccess(c, int64(count), lists, pagination)
}

func (ArticleCommentController) Banned(c *gin.Context) {
	commentID := c.Query("comment_id")
	if commentID == "" {
		utils.Error(c, -1, "评论id不能为空", http.StatusBadRequest)
		return
	}
	commentIntID, _ := strconv.Atoi(commentID)
	_, err := service.ArticleComment{}.Banned(uint(commentIntID))
	if err != nil {
		utils.Error(c, -1, err.Error(), http.StatusBadRequest)
		return
	}
	utils.Success(c, gin.H{}, http.StatusNoContent)
}

func (ArticleCommentController) Del(c *gin.Context) {
	commentID := c.Query("comment_id")
	if commentID == "" {
		utils.Error(c, -1, "评论id不能为空", http.StatusBadRequest)
		return
	}
	commentIntID, _ := strconv.Atoi(commentID)
	_, err := service.ArticleComment{}.Del(uint(commentIntID))
	if err != nil {
		utils.Error(c, -1, err.Error(), http.StatusBadRequest)
		return
	}
	utils.Success(c, gin.H{}, http.StatusNoContent)
}
